@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

.popup-content:has(#worldInfoRecommenderPopup) {
    overflow-y: auto;
}

.popup-content:has(.edit-popup) {
    overflow: visible;
    overflow-y: auto;
}

.popup-body:has(.edit-popup) {
    overflow: visible;
}

.popup-content:has(.compare-popup) {
    overflow: visible;
    overflow-y: auto;
}
.popup-body:has(.compare-popup) {
    overflow: visible;
}
dialog:has(.compare-popup) {
    max-width: 90dvw;
    min-width: var(--sheldWidth);
}

.popup-content:has(.select-entries-popup) {
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}
dialog:has(.select-entries-popup) {
    min-width: 600px;
}

#worldInfoRecommenderPopup {
    color: var(--SmartThemeBodyColor);
    font-family: var(--mainFontFamily);
    max-width: 1200px;
    margin: 0 auto;
    font-size: var(--mainFontSize);

    h2 {
        text-align: center;
        margin-bottom: 20px;
        font-weight: 500;
        color: var(--SmartThemeBodyColor);
    }

    h3 {
        font-weight: 500;
        margin-top: 0;
        margin-bottom: 15px;
        color: var(--SmartThemeBodyColor);
    }

    .container {
        display: flex;
        gap: 20px;

        @media (max-width: 768px) {
            flex-direction: column;
        }
    }

    .column {
        width: 30%;
        display: flex;
        flex-direction: column;
        gap: 15px;

        @media (max-width: 768px) {
            width: 100%;
        }
    }

    .wide-column {
        width: 70%;
        display: flex;
        flex-direction: column;
        gap: 15px;

        @media (max-width: 768px) {
            width: 100%;
        }
    }

    .card {
        background-color: var(--SmartThemeBlurTintColor);
        border-radius: 10px;
        padding: 15px;
        box-shadow: 0 2px 4px var(--SmartThemeShadowColor);
        margin-bottom: 0;
        border: 1px solid var(--SmartThemeBorderColor);
    }

    .message-options {
        .message-input {
            width: 50px;
            margin-left: 5px;
            margin-right: 5px;
        }
    }

    .entry-selection-control {
        display: flex;
        align-items: center;
        gap: 10px;
        margin-top: 10px;

        .menu_button {
            padding: 5px 10px;
            font-size: 0.9em;
            i {
                margin-right: 5px;
            }
        }
        span {
            font-size: 0.9em;
            color: var(--SmartThemeBodyColor);
            opacity: 0.8;
        }
    }

    .entry {
        background-color: var(--grey10);
        border-radius: 8px;
        padding: 15px;
        margin-bottom: 15px;
        position: relative;
        border: 1px solid var(--grey30);

        .menu {
            display: flex;
            justify-content: flex-end;
            gap: 8px;
            margin-bottom: 10px;
            flex-wrap: wrap;

            @media (max-width: 512px) {
                flex-wrap: wrap;
                justify-content: flex-end;

                .world-select {
                    order: 2;
                    margin-right: 0;
                    width: 100%;
                    max-width: 100%;
                }
            }

            .world-select {
                margin-right: auto;
                max-width: 200px;
                min-width: 150px;
                height: 30px;
                font-size: 0.9em;
                background-color: var(--SmartThemeInputColor);
                color: var(--SmartThemeInputTextColor);
                border: 1px solid var(--SmartThemeBorderColor);
                border-radius: 4px;
            }

            .menu_button {
                padding: 5px 10px;
                font-size: 0.9em;
                height: fit-content;
            }

            .add,
            .continue {
                background-color: var(--active);

                &:hover {
                    background-color: color-mix(in srgb, var(--active) 85%, white);
                }
            }

            .blacklist {
                background-color: var(--grey50);

                &:hover {
                    background-color: var(--grey70);
                }
            }

            .remove {
                background-color: var(--warning);

                &:hover {
                    background-color: color-mix(in srgb, var(--warning) 85%, white);
                }
            }
        }

        .comment {
            margin-top: 0;
            margin-bottom: 5px;
            color: var(--SmartThemeBodyColor);
            font-weight: 500;
        }

        .key {
            color: var(--SmartThemeEmColor);
            font-size: 0.9em;
            margin-bottom: 8px;
        }

        .content {
            margin-bottom: 5px;
            color: var(--SmartThemeBodyColor);
        }
    }

    .actions {
        display: flex;
        justify-content: flex-end;
        margin-bottom: 15px;

        .menu_button {
            background-color: var(--active);
            min-width: 90px;

            &:hover {
                background-color: color-mix(in srgb, var(--active) 85%, white);
            }

            &:disabled {
                opacity: 0.5;
                cursor: not-allowed;
                pointer-events: none;
            }
        }
    }

    button:disabled {
        opacity: 0.5;
        cursor: not-allowed;
        pointer-events: none;
    }

    .compare-popup {
        color: var(--SmartThemeBodyColor);
        font-family: var(--mainFontFamily);
        padding: 15px;

        h3 {
            margin-bottom: 15px;
            font-weight: 500;
            color: var(--SmartThemeBodyColor);
        }

        h4 {
            margin-bottom: 10px;
            color: var(--SmartThemeBodyColor);
        }

        .content {
            font-family: monospace;
            white-space: pre-wrap;
            padding: 15px;
            border: 1px solid var(--SmartThemeBorderColor);
            border-radius: 8px;
            background-color: var(--SmartThemeBlurTintColor);
            margin-bottom: 10px;

            span {
                &[style*="color: green"] {
                    color: var(--success) !important;
                    background-color: color-mix(in srgb, var(--success) 15%, transparent) !important;
                }

                &[style*="color: red"] {
                    color: var(--warning) !important;
                    background-color: color-mix(in srgb, var(--warning) 15%, transparent) !important;
                }

                &[style*="color: grey"] {
                    color: var(--SmartThemeBodyColor) !important;
                }
            }
        }
    }
}

.select-entries-popup {
    display: flex;
    flex-direction: column;
    gap: 15px;
    padding: 10px;
    height: 100%;

    h3 {
        margin-top: 0;
        text-align: center;
    }

    .controls {
        display: flex;
        gap: 10px;
        align-items: center;
        flex-wrap: wrap;

        .text_pole {
            flex-grow: 1;
        }
    }

    .entry-list {
        flex-grow: 1;
        overflow-y: auto;
        border: 1px solid var(--SmartThemeBorderColor);
        border-radius: 8px;
        padding: 10px;
        background-color: var(--SmartThemeChatBGColor);
    }

    .world-group {
        margin-bottom: 15px;

        h4 {
            margin: 0 0 8px 0;
            padding-bottom: 5px;
            border-bottom: 1px solid var(--SmartThemeBorderColor);
            color: var(--SmartThemeEmColor);
        }

        ul {
            list-style: none;
            padding: 0;
            margin: 0;
        }

        li {
            margin-bottom: 5px;

            label {
                display: flex;
                align-items: center;
                gap: 8px;
                cursor: pointer;
            }
        }
    }
}

/* Shared Popup Component Styles */
.popup_header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;

    h2, h3 {
        margin: 0;
    }
}

.popup_header_buttons {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

/* Revise Session Styles */
.revise-session-manager {
    display: flex;
    flex-direction: column;
    height: 100%;
    gap: 10px;
    max-height: 80vh;

    .session-list {
        flex-grow: 1;
        overflow-y: auto;
        padding: 5px;
        display: flex;
        flex-direction: column;
        gap: 10px;
    }

    .session-item {
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 10px;
        background-color: color-mix(in srgb, var(--SmartThemeBlurTintColor) 70%, var(--black100) 30%);
        border: 1px solid var(--SmartThemeBorderColor);
        border-radius: 8px;
        cursor: pointer;
        transition: 0.2s;

        &:hover {
            background-color: var(--white20a);
        }

        .session-info {
            flex-grow: 1;
            display: flex;
            flex-direction: column;
            .session-name {
                font-weight: 500;
            }
            .session-date {
                font-size: 0.8em;
                color: var(--SmartThemeEmColor);
            }
        }
    }

    .session-actions {
        padding: 10px;
        text-align: center;
        border-top: 1px solid var(--SmartThemeBorderColor);
    }
}

.revise-session-chat {
    display: flex;
    flex-direction: column;
    height: 100%;
    gap: 10px;
    max-height: 80vh;

    .chat-messages {
        flex-grow: 1;
        overflow-y: auto;
        padding: 10px;
        display: flex;
        flex-direction: column;
        gap: 5px;
        background-color: color-mix(in srgb, var(--SmartThemeBlurTintColor) 70%, var(--black100) 30%);
        border: 1px solid var(--SmartThemeBorderColor);
        border-radius: 8px;
    }

    .initial-messages-container {
        margin-bottom: 10px;
        border: 1px solid var(--SmartThemeBorderColor);
        border-radius: 8px;
        padding: 5px;

        summary {
            cursor: pointer;
            color: var(--SmartThemeEmColor);
        }

        &[open] {
            .initial-messages-content {
                margin-top: 10px;
            }
        }
    }

    .message-editor {
        padding: 10px;
        border: 1px solid var(--primary);
        border-radius: 8px;
        background: var(--black20a);

        .editor-buttons {
            display: flex;
            justify-content: flex-end;
            gap: 10px;
            margin-top: 5px;
        }
    }

    .message-bubble-wrapper {
        display: flex;
        gap: 8px;
        align-items: center;
        margin-bottom: 10px;
        position: relative;

        &.user {
            justify-content: flex-end;
            .message-actions { order: -1; }
        }
        &.assistant {
            justify-content: flex-start;
        }

        &.initial-context {
            margin-left: 10px;
            margin-right: 10px;
            margin-bottom: 5px;
        }

        .message-actions {
            display: flex;
            gap: 5px;
            flex-shrink: 0;
            opacity: 0;
            transition: opacity 0.2s;
        }

        &:hover .message-actions {
            opacity: 1;
        }

        .message-action-button {
            padding: 5px;
            height: 28px;
            width: 28px;
            flex-shrink: 0;
            background: var(--black30a);
        }
    }

    .message-bubble {
        max-width: 80%;
        padding: 10px 15px;
        border-radius: 18px;
        word-wrap: break-word;
        white-space: pre-wrap;

        &.user {
            background-color: var(--SmartThemeUserMesBlurTintColor);
            color: var(--white100);
            border-bottom-right-radius: 4px;
        }

        &.assistant {
            background-color: var(--SmartThemeBotMesBlurTintColor);
            color: var(--SmartThemeBodyColor);
            border-bottom-left-radius: 4px;
        }

        &.initial {
            width: 100%;
            max-width: 100%;
            font-size: 0.9em;
            border-radius: 8px;
            background-color: color-mix(in srgb, var(--SmartThemeBotMesBlurTintColor) 50%, transparent);
            color: var(--SmartThemeEmColor);
        }

        &.loading {
            text-align: center;
            padding: 15px;
        }
    }

    .regenerate-button-wrapper {
        display: flex;
        justify-content: center;
        padding: 5px 0;
    }

    .chat-input-area {
        display: flex;
        gap: 10px;
        align-items: flex-end;

        textarea {
            flex-grow: 1;
        }
        button {
            height: 40px;
            width: 40px;
            flex-shrink: 0;
        }
    }
}

/* Shared styles for state comparison views */
.compare-state-list {
    max-height: 60vh;
    overflow-y: auto;
    padding-right: 10px;
}

.compare-state-item {
    margin-bottom: 20px;
    border: 1px solid var(--SmartThemeBorderColor);
    border-radius: 8px;
    padding: 10px;
    background-color: var(--SmartThemeBlurTintColor);

    h4 {
        margin-top: 0;
        margin-bottom: 10px;
        text-align: center;
    }
}

.compare-state-header {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    text-align: center;
    font-weight: 500;
    margin-bottom: 5px;
    color: var(--SmartThemeEmColor);
}

.compare-state-diff-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;

    .content {
        font-family: monospace;
        white-space: pre-wrap;
        padding: 10px;
        border: 1px solid var(--SmartThemeBorderColor);
        border-radius: 6px;
        background-color: color-mix(in srgb, var(--SmartThemeBlurTintColor) 70%, var(--black100) 30%);
        min-height: 40px;
        word-break: break-word;

        span {
            &[style*="color: green"] {
                color: var(--active) !important;
                background-color: color-mix(in srgb, var(--active) 15%, transparent) !important;
            }

            &[style*="color: red"] {
                color: var(--warning) !important;
                background-color: color-mix(in srgb, var(--warning) 15%, transparent) !important;
            }

            &[style*="color: grey"] {
                color: var(--SmartThemeBodyColor) !important;
            }
        }
    }
}

/* Global Diff Styles in Compare Popup */
.global-diff {
  .diff-section {
    margin-bottom: 20px;
    h4 {
      background-color: var(--black30a);
      padding: 8px;
      border-radius: 6px;
      margin-bottom: 10px;
      border-bottom: 1px solid var(--SmartThemeBorderColor);
    }
  }

  .diff-entry {
    border-left: 3px solid;
    padding-left: 15px;
    margin-bottom: 15px;

    .diff-entry-header {
      font-weight: 500;
      margin-bottom: 8px;
      span {
        font-weight: normal;
        color: var(--SmartThemeEmColor);
        font-size: 0.9em;
      }
    }

    .diff-entry-content {
      white-space: pre-wrap;
      word-break: break-word;
      font-size: 0.9em;
      padding: 10px;
      background: var(--black10a);
      border-radius: 4px;
    }

    &.added {
      border-color: var(--active);
      .diff-entry-header { color: var(--active); }
    }
    &.removed {
      border-color: var(--warning);
      .diff-entry-header { color: var(--warning); }
      .diff-entry-content { text-decoration: line-through; }
    }
    &.changed {
      border-color: var(--primary);
    }
  }
}


/* Current State Popup Styles */
.current-state-popup {
    color: var(--SmartThemeBodyColor);
    padding: 15px;

    .popup_header {
        h3 { margin: 0; }
    }

    .current-state-content {
        max-height: 60vh;
        overflow-y: auto;
        padding: 5px;
    }

    .state-field {
        margin-bottom: 15px;

        label {
            display: block;
            font-weight: 500;
            color: var(--SmartThemeEmColor);
            margin-bottom: 5px;
        }

        .state-value {
            white-space: pre-wrap;
            word-break: break-word;
            padding: 10px;
            background: color-mix(in srgb, var(--SmartThemeBlurTintColor) 70%, var(--black100) 30%);
            border-radius: 6px;
            border: 1px solid var(--SmartThemeBorderColor);
        }

        textarea, input {
            width: 100%;
        }

        .subtle-text {
            color: var(--SmartThemeEmColor);
            font-style: italic;
        }
    }
}

.global-state-popup {
    .world-group {
        margin-bottom: 15px;
        h4 {
            margin: 0 0 8px 0;
            padding-bottom: 5px;
            border-bottom: 1px solid var(--SmartThemeBorderColor);
            color: var(--SmartThemeEmColor);
        }
    }
    .state-field-group {
        border: 1px solid var(--SmartThemeBorderColor);
        border-radius: 8px;
        padding: 10px;
        margin-bottom: 10px;
        background-color: var(--black10a);
    }
    .state-field {
        margin-bottom: 8px;
        &:last-child {
            margin-bottom: 0;
        }
        label {
            margin-bottom: 2px;
            font-size: 0.9em;
        }
        .state-value {
            padding: 5px;
            font-size: 0.95em;
        }
    }
}
